package com.newppjoke.ktnewppjoke

import android.os.Bundle
import android.text.TextUtils
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.newppjoke.ktnewppjoke.databinding.ActivityMainBinding
import com.newppjoke.ktnewppjoke.utils.NavGraphBuilder
import com.newppjoke.ktnewppjoke.view.AppBottomBar

class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener {

    private  var navController: NavController? =null
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val navView: AppBottomBar = binding.navView

        val fragment =
            supportFragmentManager.findFragmentById(R.id.nav_host_fragment)

        navController = fragment?.let { NavHostFragment.findNavController(it) }

//        setupActionBarWithNavController(navController, appBarConfiguration)

        fragment?.id?.let { NavGraphBuilder.build(navController,this, it) }
        navView.setOnNavigationItemSelectedListener(this)
//        navView.setupWithNavController(navController)
    }

    override fun onNavigationItemSelected(item: MenuItem): Boolean {
        navController?.navigate(item.itemId)
        return !TextUtils.isDigitsOnly(item.title)
    }
}